﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web;
using System.ServiceModel.Activation;
using System.IO;
using System.Xml;
using log4net;
using System.Configuration;
using ServiceLibrary.BLayer;

namespace SISMHost
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    [ServiceBehavior(Namespace = "http://CheckService.central.services.IntegraSISM.babele.csi.it")]
    public class SISM : ISISM
    {
        #region Variabili Locali

        private static log4net.ILog log;
        private static bool writeDebug = Convert.ToBoolean(ConfigurationManager.AppSettings["DEBUG"]);
        private BSIO serviceLibrary = new BSIO();

        #endregion

        #region Costruttore

        public SISM()
        {
            if (writeDebug)
            {
                LOGHelp _logHelp = LOGHelp.Instance;
                _logHelp.LoadLog4NeFromCongif();
                log = log4net.LogManager.GetLogger("Servizio");
            }
        }

        #endregion

        #region IsAlive

        public bool IsAlive()
        {
            return serviceLibrary.IsAlive();
        }

        #endregion

        #region CaricaXml

        public void CaricaXml()
        { 
            try{
                serviceLibrary.ScorriEventi();
            }
            catch (Exception ex)
            {
                if (writeDebug)
                {
                    log.Error(" # CaricaXml # " + ((ex.InnerException != null) ? ex.InnerException.ToString() : ex.Message.ToString()));
                }
            }

        }

        #endregion

        #region Test

        public void Test()
        {
            try
            {
                serviceLibrary.Test();
            }
            catch (Exception ex)
            {
                if (writeDebug)
                {
                    log.Error(" # Test # " + ((ex.InnerException != null) ? ex.InnerException.ToString() : ex.Message.ToString()));
                }
            }

        }

        #endregion

    }
}
